#ifndef _PARAMETER_H_
#define _PARAMETER_H_

#include <stdint.h>
#include <stddef.h>
#include "mlib_config.h"


/*管理参数个数*/
#define SETTINGS_MAX_NUM 		50

#define MG(X,Y) (((uint16_t)X<<8)+Y)

typedef uint32_t (*storage_wr_func)(uint32_t, uint8_t*, uint32_t);
typedef void (*settings_default_func)(void);
/*系统参数，字符串类型（以0x00结尾）*/
typedef struct {
	const char* name;			//参数名称
	char* ptr;					//参数值在SystemSettingsBuf里面对应的地址
}SystemSettings;

typedef enum{
	SETTINGS_OK,
	SETTINGS_LEN_ERROR,
	SETTINGS_CRC_ERROR,
	SETTINGS_WRITE_ERROR,
	SETTINGS_NUM_ERROR,
	SETTINGS_DATA_ERROR,
	SETTINGS_STRING_ERROR,
}settings_status_t;


typedef struct {
	/*是否初始化标识*/
	uint8_t ini_flag;
	/*内存起始地址*/
	uint32_t start_addr;
	/*存储空间大小*/
	uint32_t stroage_size;
	/*写存储器函数--需适配平台*/
	storage_wr_func storage_write;
	/*读存储器函数--需适配平台*/
	storage_wr_func storage_read;
	/*用来初始化默认参数*/
	settings_default_func default_settings;
}settings_ini;


extern SystemSettings SystemSetting[SETTINGS_MAX_NUM];
extern settings_ini si;

void System_SettingsInit(void);
uint8_t System_SettingsRestore(void);
uint8_t System_SettingsSetSingle(uint16_t num, char* data , uint16_t len);
uint8_t System_SettingsSetMulti(char* data ,uint16_t num_to_write);
uint8_t System_SettingsSave(void);
void System_SettingsReport(void);




#endif // _PARAMETER_H_


